package com.project.forlearning.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;

@Configuration
public class DruidConfig {


     @ConfigurationProperties(prefix = "spring.datasource")
     @Bean
     public DataSource druidDataSource(){
          DruidDataSource druidDataSource = new DruidDataSource();
          //配置数据库
          druidDataSource.setInitialSize(5);
          druidDataSource.setMinIdle(5);
          druidDataSource.setMaxActive(20);
          druidDataSource.setMaxWait(60000);
          druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
          druidDataSource.setMinEvictableIdleTimeMillis(300000);
          druidDataSource.setValidationQuery("SELECT 1 FROM DUAL");
          druidDataSource.setTestWhileIdle(true);
          druidDataSource.setTestOnBorrow(false);
          druidDataSource.setTestOnReturn(false);
          druidDataSource.setPoolPreparedStatements(true);
          return druidDataSource;
     }
}
